package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

@RestController("admin")
@RequestMapping("/admin/shop")
@Api(tags = "后端店铺状态")
@Slf4j
public class ShopController {
    @Autowired
    private RedisTemplate redisTemplate;
    public static final String KEY_SHOP_STATUS="SHOP_STATUS";
    @ApiOperation("后台店铺状态设置")
    @PutMapping("/{status}")
    public Result updateStatus(@PathVariable Integer status){
        ValueOperations ops = redisTemplate.opsForValue();
        ops.set(KEY_SHOP_STATUS,status);
        return Result.success();
    }
    @ApiOperation("后台店铺状态查询")
    @GetMapping("/status")
    public Result selectStatus(){
        ValueOperations ops = redisTemplate.opsForValue();
        Integer o = (Integer) ops.get(KEY_SHOP_STATUS);
        log.info("营业状态{}",o==1?"营业中":"不营业");
        return Result.success(o);
    }
}
